<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/25
 * Time: 9:26
 */

namespace app\server;
use rap\db\DB;
use rap\db\Record;

class StickPay extends Record
{
    public function addOrderInfo($data) {

        $res = DB::insert('mp_stick_pay', $data);

        return $res;
    }

    public function updateOrderInfo ($where, $data) {
        $sql = DB::update('mp_stick_pay');
        foreach ($data as $k => $v) {
            $sql = $sql->set($k, $v);
        }
        $res =$sql->where($where)->excuse();
        return $res;
    }

    public function addUserCashInfo($data) {
        $res = DB::insert('mp_stick_cash', $data);

        return $res;
    }

    public function updateUserInfo($where, $data) {
        $sql = DB::update('mp_stick_pay');
        foreach ($data as $k => $v) {
            $sql = $sql->set($k, $v);
        }
        $res =$sql->where($where)->excuse();
        return $res;
    }

    public function getUserPayInfo ($where, $field, $limit, $page) {

        $page = $page * $limit;
        $data = DB::select('mp_stick_pay sp')
            ->join('mp_stick_user su', 'sp.user_id = su.user_id', 'left')
            ->order('create_time desc')
            ->limit($page, $limit)
            ->where($where)
            ->fields($field)
            ->findAll();

        return $data;
    }

    public function updateInfo ($sql) {

        $res = DB::query($sql);

        return $res;
    }
}